var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		tabnum: 1,
		buydialogHidden: true,
		num: 1,
		isfavorite: false,
		btntype: 1,
		ggselected: [],
		ks: '',
		gwcnum: 1,
		nodata: 0,
		userinfo:[],
	},
	_onLoad: function () {
		var that = this
		var id = '';
		if (that.options && that.options.id) {
			id = that.options.id
		}
		if (that.options && that.options.scene) {
			var scene = that.options.scene
			var scenes = scene.split('_');
			if(scenes[1]){
				id = parseInt(scenes[1]);
			}
		}
		$.get('scoreshop/product', { id: id }, function (res) {
			if (res.status == 0) {
				$.alert(res.msg); return;
			}
			var product = res.product;
			var sysset = res.sysset;

			var pagecontent = JSON.parse(product.detail);
			var _bannerindex = [];
			for(var i in pagecontent){
				_bannerindex[i] = 0;
			}
			sysset.textset = that.data.textset
			that.setData({
				product: product,
				pagecontent:pagecontent,
				_bannerindex:_bannerindex,
				sysset:sysset,
				shopset:res.shopset,
				myscore:res.myscore,
				title:product.name,
				sharepic:product.pics[0],
				isfavorite:res.isfavorite,
			});

			wx.setNavigationBarTitle({
				title: product.name
			});
		})
	},
	tobuy: function (e) {
		var that = this;
		var proid = that.data.product.id;
		$.goto('/pages/scoreshop/buy?proid=' + proid);
	},
	//收藏操作
	addfavorite: function () {
		var that = this;
		var proid = that.data.product.id;
		$.post('scoreshop/addfavorite', { proid: proid,type:'scoreshop'}, function (data) {
			if (data.status == 1) {
				that.setData({ isfavorite: !that.data.isfavorite });
			}
			$.success(data.msg);
		}, '加载中');

	},
	tabClick: function (e) {
		this.setData({
			tabnum: e.currentTarget.dataset.num
		})
	},
	shareClick:function(){
		this.setData({sharetypevisible:true})
	},
	handleClickMask:function(){
		this.setData({sharetypevisible:false})
	},
}))